﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Globalization;
using System.Resources;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Collections;

namespace etimet
{
    public partial class MainForm : Form
    {

        [DllImport("User32.dll")]
        public static extern int SetForegroundWindow(int hWnd);

        public MainForm()
        {
            InitializeComponent();

            this.StartPosition = FormStartPosition.CenterScreen;

            TranslationHelper.TranslateForm(Program.conf.CurrentLang, this);
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AboutBox a = new AboutBox();
            try
            {
                a.ShowDialog();
            }
            catch (System.Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }
            finally
            {
                a.Dispose();
            }
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void optionsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OptionsForm a = new OptionsForm();
            try
            {
                DialogResult b = a.ShowDialog();
            }
            catch (System.Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }
            finally
            {
                a.Dispose();
            }

        }

        private void Form1_Shown(object sender, EventArgs e)
        {
            //notifyIcon1.ShowBalloonTip(5, "Hello!", "this is a balloon.", ToolTipIcon.Info);
        }

        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            this.BringToFront();
            SetForegroundWindow(this.Handle.ToInt32());
        }

        private void Form1_Resize(object sender, EventArgs e)
        {
            if (FormWindowState.Minimized == this.WindowState)
            {
                this.Hide();
            }
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            this.Hide();
        }

        private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.Show();
                this.WindowState = FormWindowState.Normal;
                this.Focus();
                this.BringToFront();
                SetForegroundWindow(this.Handle.ToInt32());
            }
        }

        private void Exit_toolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void Show_toolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Show();
            this.WindowState = FormWindowState.Normal;
            this.Focus();
            this.BringToFront();
            SetForegroundWindow(this.Handle.ToInt32());
        }

        private void HideStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void Hide_ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

    }
}
